fruits = {'apple', 'banana', 'orange'}
colors = set(['red', 'green', 'blue'])


print('apple' in fruits)
fruits.add('pear')
fruits.remove('banana')
fruits.discard('mango')


a = {1, 2, 3, 4}
b = {3, 4, 5, 6}

print(a | b)
print(a & b)
print(a - b)
print(a ^ b)



squares = {x**2 for x in range(10) if x%2 == 0}
print(squares)



stack = []
stack.append('A')
stack.append('B')
stack.append('C')

print(stack.pop())
print(stack.pop())
from collections import deque
queue = deque()
queue.append('A')
queue.append('B')
queue.append('C')

print(queue.popleft())
print(queue.popleft())





from collections import Counter
words = ['apple', 'banana', 'apple', 'orange', 'banana', 'apple']
word_counts = Counter(words)

print(word_counts)
print(word_counts.most_common(2))

word_counts.update(['apple'])



from collections import defaultdict

fruit_counts = defaultdict(int)
fruit_counts['apple'] += 1

students = defaultdict(list)
students['class1'].append('Alice')
students['class1'].append('Bob')


print(fruit_counts)
print(students)


from collections import namedtuple

Point = namedtuple('Point', ['x', 'y'])
p = Point(10, y=20)


print(p.x, p.y)
print(p[0], p[1])


def is_balanced(expr):
    stack = []
    mapping = {')': '(', '}': '{', ']': '['}


    for char in expr:
        if char in mapping.values():
            stack.append(char)
        elif char in mapping.keys():
            if not stack or stack.pop() != mapping[char]:
                return False
    return not stack


print(is_balanced("({[]})"))
print(is_balanced("({[]})"))


from collections import Counter
import re
text = "Python is an interpreted, high-level, general—purpose programing language."
words = re.findall(r'\w+', text.lower())

word_counts = Counter(words)
print(word_counts.most_common(3))


from collections  import deque


def max_sliding_window(nums, k):
    q = deque()
    result = []

    for i, num in enumerate(nums):
        while q and nums[q[-1]] <= num:
            q.pop()  # 移除较小的元素
        q.append(i)

        if q[0] == i - k:  # 移除窗口外的元素
            q.popleft()

        if i >= k - 1:
            result.append(nums[q[0]])

    return result

print(max_sliding_window([1,3,-1,-3,5,3,6,7], 3))  # [3,3,5,5,6,7]from collections import deque

def max_sliding_window(nums, k):
    q = deque()
    result = []

    for i, num in enumerate(nums):
        while q and nums[q[-1]] <= num:
            q.pop()  # 移除较小的元素
        q.append(i)

        if q[0] == i - k:  # 移除窗口外的元素
            q.popleft()

        if i >= k - 1:
            result.append(nums[q[0]])

    return result

print(max_sliding_window([1,3,-1,-3,5,3,6,7], 3))  # [3,3,5,5,6,7]from collections import deque

def max_sliding_window(nums, k):
    q = deque()
    result = []

    for i, num in enumerate(nums):
        while q and nums[q[-1]] <= num:
            q.pop()  # 移除较小的元素
        q.append(i)

        if q[0] == i - k:  # 移除窗口外的元素
            q.popleft()

        if i >= k - 1:
            result.append(nums[q[0]])

    return result

print(max_sliding_window([1,3,-1,-3,5,3,6,7], 3))  # [3,3,5,5,6,7]]



